# encoding: utf-8
"""
options.py

Created by Manel Rovira Trenc on 2008-06-01.
Copyright (c) 2008 __MyCompanyName__. All rights reserved.
"""

import sys
import os

from google.appengine.ext import db
import logging
import models

class utilData(object):
    """docstring for Options"""
    def __init__(self):
        pass
    
    def mem(key, time=60): 
        def decorator(fxn): 
            def wrapper(*args, **kwargs): 
                data = memcache.get(key) 
                if data is  None: 
                    data = fxn(*args, **kwargs) 
                    memcache.set(key, data, time) 
                return data 
            return wrapper 
        return decorator
    
    @mem('feed', 3600)
    def getfeed(self):
        return models.Feed.all().order('order')
    
    @mem('widget'+key, 3600)
    def w_widget(self,key):
        widget = {}
        try:
            widget = models.SidebarWidget.get(db.Key(key))
        except db.Error:
            return widget
        if widget is not None:
            return widget
    
        


